package com.appbee.article.client.presenter;

import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;

import com.appbee.article.client.ui.ArticleBox;
import com.appbee.core.client.cache.ClientCache;

@Singleton
public class ArticleBoxProvider
{
	private final ClientCache<String, ArticleBox> cache = new ClientCache<String, ArticleBox>(
			15 * 60, 50);
	private final Provider<ArticleBox> provider;

	@Inject
	public ArticleBoxProvider(Provider<ArticleBox> provider)
	{
		this.provider = provider;
	}

	public ArticleBox getByStrId(String strId)
	{
		ArticleBox articleBox = cache.get(strId);
		if (articleBox == null)
		{
			articleBox = provider.get();
			articleBox.setStrId(strId);
			cache.put(strId, articleBox);
		}
		return articleBox;
	}
}
